<?php

namespace App\Service\Cruise\Mission;

use App\Enums\BaseErrorCode;
use App\Enums\OpenShop\InvestmentPromotion\MainProcessEnum;
use App\Enums\OpenShop\InvestmentPromotion\SignOrderEnum;
use App\Enums\OpenShop\MissionTemplateEnum;
use App\Events\OpenShop\AutoRefundDecorationDepositEvent;
use App\Exceptions\Custom\ResponseHttpException;
use App\Library\Rms\RmsShopApi;
use App\Models\Appraise\AppraiseModel;
use App\Models\Common\ResourcesModel;
use App\Models\Cruise\CruiseOrderExamineLogModel;
use App\Models\Cruise\CruiseOrderInputModel;
use App\Models\Cruise\CruiseOrderInputTypeModel;
use App\Models\Cruise\CruiseOrderModel;
use App\Models\Cruise\CruiseOrderProcessModel;
use App\Models\Cruise\CruiseTaskProjectModel;
use App\Models\Cruise\CruiseTemplateModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopAddressModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSiteMissionModel;
use App\Models\OpenShop\StartBusiness\OpenShopStartBusinessModel;
use App\Models\WorkOrder\WorkOrderApplyContentModel;
use App\Remote\Rms\RmsUserRemote;
use App\Service\Cruise\CruiseProject\CruiseProjectInputService;
use App\Service\OpenShop\Feishu\BaseService;
use App\Service\OpenShop\Feishu\MessageSendService;
use App\Service\OpenShop\Feishu\MessageService;
use App\Service\OpenShop\Feishu\OrganizationManageService;
use App\Service\OpenShop\Feishu\ShopTagsService;
use App\Service\OpenShop\Feishu\SpaceDesignService;
use App\Service\OpenShop\Feishu\StartBusinessService;
use App\Service\Rms\ShopService;
use App\Service\WorkOrder\Appraise\NotifyService;
use App\Support\CustomForm\AttributeCruiseSupport;
use App\Support\CustomForm\AttributeSupport;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class CruiseOrderInputService
{
    private CruiseOrderModel $cruiseOrderModel;

    public function __construct(CruiseOrderModel $cruiseOrderModel)
    {
        $this->cruiseOrderModel = $cruiseOrderModel;
    }

    /**
     * 命中需要记录cruise_order_modules的巡检项的inputType
     * @var array
     */
    private array $hitInputTypes = [];

    /**
     * 初始化模板下所有项目
     * @param CruiseOrderModel $cruiseOrderModel
     * @return string
     */
    private function initInputObjectJson(int $templateId): string
    {
        $template = CruiseTemplateModel::query()->find($templateId);
        if (!$template) {
            throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null,
                "获取巡店模板失败:{$templateId}");
        }

        // projectId->field的map
        $projectId_field_mapping = [];

        return $template->positionsRel->map(function ($position) use (&$projectId_field_mapping) {

            return [
                'positionName' => $position->name,
                'projects'     => $position->positionProjectMappingsRel->map(function ($mapping) use (
                    &
                    $projectId_field_mapping
                ) {

                    $projectModel = $mapping->projectRel;
                    if ($projectModel->status == CruiseTaskProjectModel::STATUS_OFF) {
                        return null;
                    }

                    if (in_array($projectModel->inputType, CruiseOrderInputTypeModel::SUPPORT_INPUT_TYPES)) {
                        $this->hitInputTypes[] = $projectModel->inputType;
                    }

                    $inputObject = unserialize($projectModel->inputObject);

                    // 如果关联了后面的字段，这里就会丢失relations
                    $projectId_field_mapping[$mapping->projectId] = $inputObject->getInputName();

                    // 添加tips
                    if ($projectModel->tipsType == AttributeSupport::INPUT_TYPE_STRING) {
                        $inputObject->setCustomAttribute(["desc", $projectModel->tipsContent]);
                    } elseif ($projectModel->tipsType == AttributeSupport::INPUT_TYPE_IMG_GROUP) {

                        // 资源素材
                        $resource = (array)ResourcesModel::getModuleBusinessResources(ResourcesModel::MODULE_TYPE_CRUISE,
                            ResourcesModel::BUSINESS_CRUISE_PROJECT_TIPS, $projectModel->id, ['tipsResource']);
                        $inputObject->setCustomAttribute(["descImg", $resource['tipsResource']]);
                    } elseif ($projectModel->tipsType == AttributeSupport::INPUT_TYPE_STRING_IMG_GROUP) {

                        // 资源素材
                        $resource = (array)ResourcesModel::getModuleBusinessResources(ResourcesModel::MODULE_TYPE_CRUISE,
                            ResourcesModel::BUSINESS_CRUISE_PROJECT_TIPS, $projectModel->id, ['tipsResource']);
                        $inputObject->setCustomAttribute(["desc", $projectModel->tipsContent])
                                    ->setCustomAttribute(["descImg", $resource['tipsResource']]);
                    }

                    // relations
                    if ($mapping->relationProjectId) {
                        $relationField = $projectId_field_mapping[$mapping->relationProjectId] ?? '';
                        $inputObject->setRelations([$relationField, json_decode($mapping->relationOptions, true)]);
                    }

                    return serialize($inputObject);

                })->filter()->values()->toArray(),
            ];
        })->toJson(JSON_UNESCAPED_UNICODE);
    }

    public function initOrderInput(int $templateId)
    {
        $input = CruiseOrderInputModel::query()->updateOrCreate(['orderId' => $this->cruiseOrderModel->id, 'templateType' => CruiseTemplateModel::TYPE_1], [
//            'templateType'    => CruiseTemplateModel::TYPE_1,
            'sysTemplate'     => CruiseTemplateModel::SYS_TEMPLATE_1,
            'userContentJson' => json_encode([]),
            'inputObjectJson' => $this->initInputObjectJson($templateId)
        ]);

        // 支持组件
        if ($this->hitInputTypes) {
            $hits = collect($this->hitInputTypes)->unique()->values()->map(function ($item) {
                return [
                    'orderId'   => $this->cruiseOrderModel->i,
                    'inputType' => $item,
                    'templateType' => CruiseTemplateModel::TYPE_1,
                ];
            })->toArray();

            CruiseOrderInputTypeModel::query()->insert($hits);
        }

        return $input;
    }

    /**
     * 保存用户填写内容
     * @param CruiseOrderInputModel $cruiseOrderInputModel
     * @param string $field
     * @param $value
     * @return void
     */
    public function saveUserContentJson(int $userId, string $field, $value): void
    {
        // 状态校验
        if (!in_array($this->cruiseOrderModel->status,
            [CruiseOrderModel::STATUS_NOT_SUBMIT, CruiseOrderModel::STATUS_NOT_MODIFY])) {
            $statusText = CruiseOrderModel::CRUISE_STATUS_MAPPING[$this->cruiseOrderModel->status] ?? $this->cruiseOrderModel->status;
            throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null, "任务状态错误，当前状态:" . $statusText);
        }

        // 角色校验
        $handler = $this->cruiseOrderModel->getCurrentHandlerInfo($this->cruiseOrderModel->status);
        if ($userId != $handler['id']) {
            throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null, "您无权操作，当前处理人：{$handler['name']}");
        }

        DB::beginTransaction();

        // 锁死-防止多个进程同时修改userContentJson
        $cruiseOrderInputModel = CruiseOrderInputModel::query()->where('orderId', $this->cruiseOrderModel->id)->where('templateType', $this->cruiseOrderModel->type)->lockForUpdate()->first();

        // 校验字段是否存在
        $inputType  = '';
        $checkField = function () use ($cruiseOrderInputModel, $field, &$inputType) {
            foreach ($cruiseOrderInputModel->inputObjectJsonArr as $projects) {
                foreach ($projects['projects'] as $project) {
                    $projectObj = unserialize($project);
                    if ($projectObj->getInputName() == $field) {
                        $inputType = $projectObj->getInputType();
                        return true;
                    }
                }
            }

            DB::rollBack();
            throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null, "不存在的field:{$field}");
        };

        $checkField();

        $userContentJsonArr = $cruiseOrderInputModel->userContentJsonArr;

        if (in_array($inputType, [AttributeSupport::INPUT_TYPE_IMG_GROUP, AttributeSupport::INPUT_VIDEO])) {

            // 素材
            $resources = collect($value)->map(function ($item) {
                $item = ltrim(parse_url($item, PHP_URL_PATH), '/');
                return $item;
            })->toArray();

            ResourcesModel::moduleBusinessSingleResourcesUpdate(
                ResourcesModel::MODULE_TYPE_CRUISE,
                ResourcesModel::BUSINESS_CRUISE_ORDERS,
                $field,
                $this->cruiseOrderModel->id,
                $resources,
                1
            );

        } else {

            if (!$userContentJsonArr) {
                $userContentJsonArr = [];
            }

            $userContentJsonArr[$field] = $value;

            $cruiseOrderInputModel->userContentJson = json_encode($userContentJsonArr, true);

            $cruiseOrderInputModel->save();
        }

        DB::commit();
    }

    /**
     * 校验用户是否有编辑权限
     * @param int $userId
     * @param bool $permissionCheck
     * @return bool
     */
    private function permissionCheck(int $userId, bool $permissionCheck): bool
    {
        if ($permissionCheck) {

            // 已完成，禁止编辑
            if ($this->cruiseOrderModel->status == CruiseOrderModel::STATUS_COMPLETE) {
                return false;
            }

            $handlerUserId = $this->cruiseOrderModel->getCurrentHandlerInfo($this->cruiseOrderModel->status)['id'];
            if ($handlerUserId == $userId) {
                return true;
            }
        }

        return false;
    }

    /**
     * 获取项目input
     * @param CruiseOrderInputModel $cruiseOrderInputModel
     * @return array
     */
    public function getInputObjectFill(int $userId, bool $permissionCheck): array
    {
        $sysTemplate           = (int)CruiseTemplateModel::query()
                                                         ->where('id', $this->cruiseOrderModel->templateId)
                                                         ->value('sysTemplate');
        $cruiseOrderInputModel = CruiseOrderInputModel::getData($sysTemplate, $this->cruiseOrderModel->id);

        $cruiseOrderInput = $cruiseOrderInputModel->inputObjectJsonArr;
        $userContentArr   = $cruiseOrderInputModel->userContentJsonArr;

        // 资源素材
        $resource = (array)ResourcesModel::getModuleBusinessResources(ResourcesModel::MODULE_TYPE_CRUISE,
            ResourcesModel::BUSINESS_CRUISE_ORDERS, $cruiseOrderInputModel->orderId, []);

        // 编辑权限校验
        $permissionCheck = $this->permissionCheck($userId, $permissionCheck);

        foreach ($cruiseOrderInput as &$positions) {
            foreach ($positions['projects'] as &$project) {
                $projectObj = unserialize($project);

                $inputName = $projectObj->getInputName();
                $inputType = $projectObj->getInputType();

                if (isset($userContentArr[$inputName])) {
                    $projectObj->setValue($userContentArr[$inputName]);
                } elseif (isset($resource[$inputName])) {
                    $projectObj->setValue($resource[$inputName]);
                } else {

                    // 默认返回空字符串不给null
                    if (in_array($inputType,
                        [AttributeSupport::INPUT_TYPE_STRING, AttributeSupport::INPUT_TYPE_TEXT])) {
                        $projectObj->setValue("");
                    }
                }

                // 没权限置为 - disable
                if (!$permissionCheck || $this->cruiseOrderModel->status == CruiseOrderModel::STATUS_NOT_REVIEW) {
                    $projectObj->setCustomAttribute(["disabled", true]);
                }

                $project = $projectObj->build();
            }
        }

        // 设计效果图 - 有的话就嵌入在第一个input
        $effectImg = SpaceDesignService::handleSoftData($this->cruiseOrderModel->orderNo)['effectImg'] ?? [];
        if ($effectImg) {
            $effectImgObj = (new CruiseProjectInputService(\App\Support\CustomForm\Attribute\AttributeSupport::INPUT_TYPE_IMG_GROUP,
                'effectImg', '效果图'))
                ->setRequired(false)
                ->prepareAttribute()
                ->setValue($effectImg)
                ->setCustomAttribute(["disabled", true])
                ->build();

            array_unshift($cruiseOrderInput[0]['projects'], $effectImgObj);
        }

        return [
            'cruiseId' => $this->cruiseOrderModel->id,
            'edit'     => $permissionCheck,
            'status'   => $this->cruiseOrderModel->status,
            'lists'    => $cruiseOrderInput
        ];
    }

    /**
     * 用户提交表单
     * @return void
     */
    public function submitOrder(int $userId): void
    {
        // 状态校验
        if (!in_array($this->cruiseOrderModel->status,
            [CruiseOrderModel::STATUS_NOT_SUBMIT, CruiseOrderModel::STATUS_NOT_MODIFY])) {
            $statusText = CruiseOrderModel::CRUISE_STATUS_MAPPING[$this->cruiseOrderModel->status] ?? $this->cruiseOrderModel->status;
            throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null, "任务状态错误，当前状态:" . $statusText);
        }

        // 角色校验
        $handler = $this->cruiseOrderModel->getCurrentHandlerInfo($this->cruiseOrderModel->status);
        if ($userId != $handler['id']) {
            throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null, "您无权操作，当前处理人：{$handler['name']}");
        }

        $sysTemplate           = (int)CruiseTemplateModel::query()
                                                         ->where('id', $this->cruiseOrderModel->templateId)
                                                         ->value('sysTemplate');
        $cruiseOrderInputModel = CruiseOrderInputModel::getData($sysTemplate, $this->cruiseOrderModel->id);

        // TODO 校验参数

        $checkField = function () use ($cruiseOrderInputModel) {
            foreach ($cruiseOrderInputModel->inputObjectJsonArr as $projects) {
                foreach ($projects['projects'] as $project) {
                    $projectObj = unserialize($project);

                    // required
                    $required = $projectObj->validateSupport->required ?? false;
                    if ($required && !isset($cruiseOrderInputModel->userContentJsonArr[$projectObj->getInputName()])) {
                        throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null, "必填");
                    }
                }
            }
        };

        $checkField();

        DB::beginTransaction();

        $this->cruiseOrderModel->status = CruiseOrderModel::STATUS_NOT_REVIEW;
        $this->cruiseOrderModel->save();

        // process
        CruiseOrderProcessModel::query()->create([
            'cruiseOrderId' => $this->cruiseOrderModel->id,
            'step'          => CruiseOrderProcessModel::PROCESS_SUBMITTED,
            'status'        => CruiseOrderProcessModel::STATUS_OK,
            'type'          => $this->cruiseOrderModel->type,
        ]);

        // 更新handlerId
        $this->cruiseOrderModel->getCurrentHandlerInfo($this->cruiseOrderModel->status);

        try {

            // 帮扶数据同步至start_business
            list($params, $_) = $this->prepareStartBusinessParam($cruiseOrderInputModel);
            OpenShopStartBusinessModel::query()
                                      ->where("orderNo", $params->orderNo)
                                      ->update(array_merge([
                                          "submitTime"   => time(),
                                          "step"         => MainProcessEnum::START_BUSINESS_SUBMIT,
                                          "createdAt"    => time(),
                                          "createdByUid" => $userId
                                      ], (array)$params));

        } catch (\Exception $e) {
            Log::warning($e);
        }

        DB::commit();

        // 帮扶任务消息
        CruiseOrderInputService::helpSendFs($this->cruiseOrderModel->orderNo, CruiseOrderModel::STATUS_NOT_REVIEW);
    }

    /**
     * 审核
     * @return void
     */
    public function audit(int $userId, string $userName, int $auditStatus, string $auditContent): void
    {
        if (!in_array($this->cruiseOrderModel->status, [CruiseOrderModel::STATUS_NOT_REVIEW])) {
            $statusText = CruiseOrderModel::CRUISE_STATUS_MAPPING[$this->cruiseOrderModel->status] ?? $this->cruiseOrderModel->status;
            throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null, "任务状态错误，当前状态:" . $statusText);
        }

        // 角色校验
        $handler = $this->cruiseOrderModel->getCurrentHandlerInfo($this->cruiseOrderModel->status);
        if ($userId != $handler['id']) {
            throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null, "您无权操作，当前处理人：{$handler['name']}");
        }

        DB::beginTransaction();

        // order
        if ($auditStatus == CruiseOrderProcessModel::STATUS_OK) {
            $this->cruiseOrderModel->status = CruiseOrderModel::STATUS_COMPLETE;
        } else {
            $this->cruiseOrderModel->status = CruiseOrderModel::STATUS_NOT_MODIFY;
        }
        $this->cruiseOrderModel->save();

        // 插入process记录
        $processId = CruiseOrderProcessModel::query()->create([
            'cruiseOrderId' => $this->cruiseOrderModel->id,
            'step'          => CruiseOrderProcessModel::PROCESS_REVIEWED,
            'status'        => $auditStatus,
            'type'          => $this->cruiseOrderModel->type,
        ])->id;

        // 插入examine记录
        CruiseOrderExamineLogModel::query()->create([
            'processId' => $processId,
            'content'   => $auditContent,
            'status'    => $auditStatus,
        ]);

        if ($auditStatus == CruiseOrderProcessModel::STATUS_OK) {
            CruiseOrderProcessModel::query()->create([
                'cruiseOrderId' => $this->cruiseOrderModel->id,
                'step'          => CruiseOrderProcessModel::PROCESS_COMPLETED,
                'status'        => CruiseOrderProcessModel::STATUS_OK,
                'type'          => $this->cruiseOrderModel->type,
            ]);
        }

        // 更新handlerId
        $this->cruiseOrderModel->getCurrentHandlerInfo($this->cruiseOrderModel->status);

        DB::commit();

        if ($auditStatus == CruiseOrderProcessModel::STATUS_OK) {

            $userInfo = (object)[
                'id'       => $userId,
                'username' => $userName,
            ];

            $sysTemplate           = (int)CruiseTemplateModel::query()
                                                             ->where('id', $this->cruiseOrderModel->templateId)
                                                             ->value('sysTemplate');
            $cruiseOrderInputModel = CruiseOrderInputModel::getData($sysTemplate, $this->cruiseOrderModel->id);

            list($params, $attach) = $this->prepareStartBusinessParam($cruiseOrderInputModel);

            // 完成开业报告 - 旧逻辑兼容
            StartBusinessService::submit($userInfo, $params, $attach);

            // 审核通过消息
            CruiseOrderInputService::helpSendFs($this->cruiseOrderModel->orderNo, CruiseOrderModel::STATUS_COMPLETE);

            //自动发起装修保证金退还
            Log::info("表单提交自动发起装修保证金退还", ["orderNo" => $this->cruiseOrderModel->orderNo]);
            event(new AutoRefundDecorationDepositEvent($this->cruiseOrderModel->orderNo));

            //开业阶段-在「开业报告提交审核」完成之后，进行推送 评价消息
            NotifyService::notify($this->cruiseOrderModel->orderNo, AppraiseModel::TYPE_OPENSHOP_OPENING, 0, $this->cruiseOrderModel->shopId);

            // 审核通过后,更新标签
            (new ShopTagsService($this->cruiseOrderModel->orderNo))->removeTagsAfterPrepareStartBusiness();
        } else {

            // 被驳回消息
            CruiseOrderInputService::helpSendFs($this->cruiseOrderModel->orderNo, CruiseOrderModel::STATUS_NOT_MODIFY,
                $auditContent);
        }
    }

    /**
     * 帮扶任务字段 => 开业报告
     * @param CruiseOrderInputModel $cruiseOrderInputModel
     * @return object[]
     */
    private function prepareStartBusinessParam(CruiseOrderInputModel $cruiseOrderInputModel): array
    {
        // 根据field查找项目中，待business_three的组件。如何原项目被删了，这里会找不到
        $fields             = array_keys($cruiseOrderInputModel->userContentJsonArr);
        $startBusinessField = CruiseTaskProjectModel::query()
                                                    ->where('inputType', AttributeCruiseSupport::INPUT_TYPE_BUSINESS_THREE)
                                                    ->whereIn('inputField', $fields)
                                                    ->value('inputField') ?? '';

        $resources = [];
        ResourcesModel::query()
                      ->where("module", ResourcesModel::MODULE_TYPE_CRUISE)
                      ->where("business", ResourcesModel::BUSINESS_CRUISE_ORDERS)
                      ->where("businessId", $this->cruiseOrderModel->id)
                      ->select('name', 'url')
                      ->get()
                      ->each(function ($item) use (&$resources) {
                          $resources[$item->name][] = picturePath($item->url);
                      });

        $params = (object)[
            'orderNo'           => $this->cruiseOrderModel->orderNo,
            'startBusinessTime' => (int)strtotime($cruiseOrderInputModel->userContentJsonArr[$startBusinessField] ?? ''),
            'eatInTotal'        => (int)($cruiseOrderInputModel->userContentJsonArr['shi_fou_tang_shi_wei_g78ebl'] ?? 0),
            'staffCount'        => (int)($cruiseOrderInputModel->userContentJsonArr['yuan_gong_shu_liang_wei_76kDHP'] ?? 0),
            'sellChannel'       => json_encode($cruiseOrderInputModel->userContentJsonArr['zhi_shou_dong_xian_duo_OXxT90'] ?? []),
            'monthlyWages'      => 100 * (int)($cruiseOrderInputModel->userContentJsonArr['yue_gong_zi_zong_jin_e_TIpyu0'] ?? 0),
            'startShopPic'      => json_encode($resources['kai_ye_huo_bao_tu_pian_pERB1G'] ?? []),
            'startHotMv'        => json_encode($resources['kai_ye_huo_bao_shi_pin_Lc7Z2O'] ?? []),
        ];

        $attach = (object)[];

        return [$params, $attach];
    }


    /**
     * 帮扶的飞书消息
     * @param string $orderNo
     * @param int $status
     * @param string $auditContent
     * @return void
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function helpSendFs(string $orderNo, int $status, string $auditContent = ''): void
    {
        $cruiseModel = CruiseOrderModel::query()->where('orderNo', $orderNo)->where('type', CruiseTemplateModel::TYPE_1)->first();
        if (!$cruiseModel) {
            return;
        }
        $url          = BaseService::getCruiseTaskDetailUrl($cruiseModel->id);
        $templateName = (string)CruiseTemplateModel::query()->where('id', $cruiseModel->templateId)->value('name');

        $shopInfo = (new RmsShopApi())->getShopByIds([$cruiseModel->shopId],
                ['id', 'shopCode', 'name'])['data']['shopList'][0] ?? [];
        $shopCode = $shopInfo['shopCode'] ?? 0;
        $shopName = $shopInfo['name'] ?? '';

        $mission = OpenShopSiteMissionModel::query()
                                           ->where('orderNo', $orderNo)
                                           ->where('stepStatus', MissionTemplateEnum::STEP_STATUS_18)
                                           ->first();
        $startAt = $mission->createdAt->toDateTimeString();
        $endAt   = date('Y-m-d H:i:s', $mission->expiredAt);

        $userId               = $cruiseModel->getCurrentHandlerInfo($status)['id'];
        $userInfo             = RmsUserRemote::getRmsUserByIds([$userId])[0];
        $userName             = $userInfo['username'] ?? '';
        $receiverFeishuUserId = $userInfo['feishuUserId'] ?? '';

        $missionSuffix = CruiseOrderModel::CRUISE_STATUS_MAPPING[$status] ?? '';
        $missionName   = "【{$templateName}】{$missionSuffix}";

        switch ($status) {
            case CruiseOrderModel::STATUS_NOT_SUBMIT:
            case CruiseOrderModel::STATUS_NOT_REVIEW:
                $fs = new MessageSendService();
                $fs->setText(MessageService::DEFAULT_STAY_TITLE)
                   ->setField('任务名称', $missionName)
                   ->setField('门店编号', $shopCode)
                   ->setField('门店名称', $shopName)
                   ->setField('任务处理人', $userName)
                   ->setField('任务创建时间', $startAt)
                   ->setField('任务截止时间', $endAt)
                   ->setReceiveFeiShuIds([$receiverFeishuUserId])
                   ->setUrl($url)
                   ->send();
                break;

            case CruiseOrderModel::STATUS_NOT_MODIFY:

                $fs = new MessageSendService();
                $fs->setText(MessageService::DEFAULT_STAY_TITLE)
                   ->setField('任务名称', $missionName)
                   ->setField('门店编号', $shopCode)
                   ->setField('门店名称', $shopName)
                   ->setField('审核结果', '被驳回')
                   ->setField('审核意见', $auditContent)
                   ->setField('任务创建时间', $startAt)
                   ->setField('任务截止时间', $endAt)
                   ->setReceiveFeiShuIds([$receiverFeishuUserId])
                   ->setUrl($url)
                   ->send();
                break;
            case CruiseOrderModel::STATUS_COMPLETE:
                $fs = new MessageSendService();
                $fs->setText("【审核已通过！】")
                   ->setField('门店编号', $shopCode)
                   ->setField('门店名称', $shopName)
                   ->setField('任务创建时间', $startAt)
                   ->setField('任务截止时间', $endAt)
                   ->setReceiveFeiShuIds([$receiverFeishuUserId])
                   ->setUrl($url)
                   ->send();
                break;
        }
    }
}
